<!-- templates/index.html -->
{% extends 'base.html' %}

{% block title %}主页 - DCO Webhook{% endblock %}

{% block content %}
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1>DCO Webhook 数据查询</h1>
        <a href="{{ url_for('view_events') }}" class="btn btn-primary">高级筛选</a>
    </div>
    <form id="queryForm" method="get" action="{{ url_for('index') }}" class="row g-3 mb-4">
        <div class="col-md-6">
            <input type="text" id="queryInput" name="query" class="form-control" placeholder="输入仓库名称或 Pusher" value="{{ request.args.get('query', '') }}">
        </div>
        <div class="col-md-2">
            <button type="submit" class="btn btn-success w-100">查询</button>
        </div>
    </form>

    {% if results %}
        <div class="table-responsive">
            <table class="table table-striped table-hover">
                <thead class="table-dark">
                    <tr>
                        <th>ID</th>
                        <th>仓库</th>
                        <th>所有者</th>
                        <th>Pusher</th>
                        <th>Ref</th>
                        <th>Before SHA</th>
                        <th>After SHA</th>
                        <th>接收时间</th>
                    </tr>
                </thead>
                <tbody>
                    {% for event in results %}
                        <tr>
                            <td>{{ event.id }}</td>
                            <td>{{ event.repository_name }}</td>
                            <td>{{ event.repository_owner }}</td>
                            <td>{{ event.pusher }}</td>
                            <td>{{ event.ref }}</td>
                            <td><code>{{ event.before_sha[:7] }}</code></td>
                            <td><code>{{ event.after_sha[:7] }}</code></td>
                            <td>{{ event.received_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    {% else %}
        <div class="alert alert-warning" role="alert">
            没有找到相关数据。
        </div>
    {% endif %}
{% endblock %}
